package com.tianqu.tms.www.transfer.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.IntegralRegister;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.www.transfer.actionform.TransferRgActionForm;
import com.tianqu.tms.www.transfer.viewhelper.TransferRgInputViewHelper;

/**
 * 积分管理
 * 
 * @author Administrator
 * 
 */
public class IntegralManagementSearchResultAction extends TmsAction {
	private Logger logger = Logger
			.getLogger(IntegralManagementSearchResultAction.class);
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was start.");
		TransferRgActionForm inForm = (TransferRgActionForm) form;
		TransferRgInputViewHelper view = new TransferRgInputViewHelper();
		view.setSerial(inForm.getSerial());
		//对流水号进行判断
		TransferAcceptedInfo accept = new TransferAcceptedInfo();
		accept = accept.getAcceptInfoBySerial(inForm.getSerial(),"");
		
		IntegralRegister register = new IntegralRegister();
		register = register.getIntegralRegisterInfoBySerial(inForm.getSerial(),2,0);
		if(register != null)
		{
			setErrorsToRequest(request, TmsConstants.IM017, null);
			return mapping.getInputForward();
		}
		if(accept!=null)
		{
			
			if(accept.getCheckPrice() == 0 && accept.getTransferPrice() == 0)
			{
				setErrorsToRequest(request, TmsConstants.U1039, null);
				return mapping.getInputForward();	
			}
			// 流水号、过户状态、业务类型值从关联的过户业务信息表（tms_transfer_accepted_info）的车辆流水号（serial）、车辆过户状态（status）、车辆分类（carClass）
			// 流程表收费、交易票收费对应值从关联的过户业务财务信息表（tms_transfer_finance_info）的流程表收费金额（checkPrice）、交易票收费金额（transferPrice）；显示格式“###，###”
			view.setSerial(accept.getSerial());
			view.setStatus(String.valueOf(accept.getStatus()));
			view.setCarClass(accept.getCarClass());
			view.setLicensePlate(accept.getLicensePlate());
			view.setVin(accept.getVin());
			// 流程表收费金额（checkPrice）
			if(accept.getCheckPrice() > 0)
			{
				view.setCheckPrice(StringUtil.addDH(String.valueOf(accept.getCheckPrice())));
			}else{
				view.setCheckPrice("");
			}
			// 交易票收费金额（transferPrice）
			if(accept.getTransferPrice() > 0)
			{
				view.setTransferPrice(StringUtil.addDH(String.valueOf(accept.getTransferPrice())));
			}else{
				view.setTransferPrice("");
			}
			//add by huangheli at 20151012 start
			//view.setPrice(StringUtil.addMoneyPeriodComma(String.valueOf(accept.getPrice())));
			//view.setTransferPrice(StringUtil.addMoneyPeriodComma(String.valueOf(accept.getTransferPrice())));
			//add by huangheli at 20151012 end
		}else{
			/*view.setLicensePlate("");
			view.setPrice("");
			view.setTransferPrice("");
			view.setStatus("");
			view.setPrice("");
			view.setTransferPrice("");*/
			//流水号不存在
			setErrorsToRequest(request, TmsConstants.IM022, null);
			return mapping.getInputForward();
		}
		//add by huangheli at 20151012 start
		//view.setChargeType("交易票缴费获得积分");
		//add by huangheli at 20151012 end
		uc.setAttribute(TmsConstants.VIEWHELP, view);
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
